#ifndef ITEMROOT_H
#define ITEMROOT_H


#include "models_global.h"
#include "AbstractItem.h"


#include <QSharedData>
#include <QSharedDataPointer>



class MODELSSHARED_EXPORT RootItem : public AbstractItem
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:
        Data()
        {
            dirty = false;
        }

        Data(const Data& other) : QSharedData(other)
        {
            dirty = other.dirty;
            filePath = other.filePath;
        }

        bool    dirty;
        QString filePath;
    };


public:

    enum DataType
    {
        DataType_FIRST = AbstractItem::DataType_LAST + 1,
        FileData = DataType_FIRST,
        DataType_LAST = FileData
    };

    Q_INVOKABLE RootItem(QObject *parent = 0);
    Q_INVOKABLE RootItem(const QString& name, QObject* parent = 0);
    RootItem(const RootItem& other) : AbstractItem(other)
    {
        d = other.d;
    }

    virtual int fieldCount() const;
    virtual QString fieldName(const int &field) const;
    virtual int field(const QString &field_name) const;

    void setFilePath(const QString& file_path);
    QString filePath() const;

    bool isDirty() const;


public slots:

    void setDirty(const bool& dirty = true);


protected:

    virtual void setCustomData(const int &field, const QVariant &data);
    virtual QVariant customData(const int &field, int role = Qt::DisplayRole) const;


private:

    QSharedDataPointer<Data> d;

    friend class RootItem;

};


Q_DECLARE_METATYPE(RootItem*);

#define IS_ROOT(item) (QMetaType::type("RootItem") == QMetaType::type(item->metaObject()->className()))

#endif // ITEMROOT_H


